#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "Key.h"
#include "LED.h"
#include "OLED.h"
#include "Timer.h"
/*定时器实现按键扫描*/
/*原理是每5ms中断扫描依次按键，当key产生变化，连续记录三次*/

uint16_t Num = 0;
uint8_t Key_Val = 2;

int main(void)
{
	OLED_Init();
	Timer_Init();
	Key_Init();
	LED_Init();
	OLED_ShowNum(1, 1, Num, 3);
	while (1)
	{
		if (Time_5ms)
		{
			Time_5ms = 0;
			Key_Val = Key_Scan();
			// switch (Key_Val)
			// {
			// 	case 0:
			// 		OLED_ShowString(1, 1, "Key Down");
			// 		LED1_On();
			// 		break;
			// 	case 1:
			// 		OLED_ShowString(1, 1, "Key Up  ");
			// 		LED1_Off();
			// 		break;			
			// }
			switch (Key_Event(Key_Val))
			{
				case 0:
					OLED_ShowString(1, 1, "Single");
					LED1_On();
					break;
				case 1:
					OLED_ShowString(1, 1, "Long  ");
					LED1_Off();
					break;	
				case 2:
					OLED_ShowString(1, 1, "Double");
					break;	
			}
		}
		if (Time_1000ms)
		{
			Time_1000ms = 0;
			Num++;
			OLED_ShowNum(2, 1, Num, 3);
		}
	}
}
